package com.renfei.multimediatask.ui.task9.encodec;

import android.graphics.ImageFormat;
import android.media.MediaCodec;
import android.media.MediaFormat;
import android.media.MediaMuxer;
import android.os.Environment;
import android.util.Log;

import java.io.IOException;
import java.lang.ref.WeakReference;
import java.nio.ByteBuffer;
import java.util.concurrent.ArrayBlockingQueue;

public abstract class MediaEncoder {
    private static final boolean DEBUG = true;
    private static final String TAG = "BaseEncodec";


    private int muxerTrackCount = 0;

    protected WeakReference<MediaManager> managerWeak;


    public MediaEncoder(MediaManager mediaManager) {
        managerWeak = new WeakReference<>(mediaManager);
        managerWeak.get().addEncoder(this);
    }


    //通过抽象方法， audio  与video编码器有不同的实现
    abstract void prepare();


    void startRecording() {
        Log.e(TAG, "MediaEncoder    : startRecording");
    }

    void stopRecording() {
        Log.e(TAG, "MediaEncoder    : stopRecording");
        managerWeak.get().stop();
    }


    void release() {
    }

    protected long prevOutputPTSUs = 0;

    protected long getPTSUs() {
        long result = System.nanoTime() / 1000L;
        if (result < prevOutputPTSUs)
            result = (prevOutputPTSUs - result) + result;
        return result;
    }

}
